<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>监听 多个 ref 变量</title>
</head>
<body>
<div id="app">
    <h1>{{ count }}</h1>
    <button @click="buttonClicked">点击+1</button>

    <h1>{{ info }}</h1>
    <button @click="btnClicked">点击+1</button>
</div>
<script type="module">
    import {createApp, ref, watch} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let count = ref(0)
            let info = ref("Hello, World！")

            /*watch(
                count,
                function (value) {
                    console.log("count 的值发生了变化：" + value);
                },
            )

            watch(
                info,
                function (value) {
                    console.log("info 的值发生了变化：" + value);
                },
            )*/

            watch(
                [count, info],
                function (value) {
                    // console.log("变量的值发生了变化：" + value);
                    console.log("变量的值发生了变化：");
                    console.log(value);
                }
            )


            function buttonClicked() {
                count.value += 1
            }

            function btnClicked() {
                info.value += "Hello, World!"
            }

            return {
                count,
                buttonClicked,
                info,
                btnClicked,
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>